package com.h3bpm.web.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @author leo
 */
public class DateUtils {

    private static final Logger log = LoggerFactory.getLogger(DateUtils.class);

    public static String getQuarter(int month){
        String quarter=null;
        switch (month){
            case 1:
            case 2:
            case 3:
                quarter= "第一季度";
                break;
            case 4:
            case 5:
            case 6:
                quarter= "第二季度";
                break;
            case 7:
            case 8:
            case 9:
                quarter= "第三季度";
                break;
            case 10:
            case 11:
            case 12:
                quarter= "第四季度";
                break;
        }
        return quarter;
    }

    public static String getNowQuarter() {
        Calendar cale = Calendar.getInstance();
        int month = cale.get(Calendar.MONTH) + 1;
        return getQuarter(month);
    }

    /**
     * 比较两个日期哪个早，哪个晚
     * @param time1
     * @param time2
     * @return
     */
    public static  boolean timeCompare(String time1, String time2) {
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            //将字符串形式的时间转化为Date类型的时间
            Date a = sdf.parse(time1);
            Date b = sdf.parse(time2);
            if (a.before(b)) {
                log.info("比较两个日期 a 早，b 晚, 执行成功");
                return true;
            } else {
                log.info("比较两个日期 b 早，a 晚, 执行成功");
                return false;
            }
        } catch (Exception e) {
            log.info("比较两个日期哪个早，哪个晚, 执行失败");
            e.printStackTrace();
        }

        return false;
    }

}
